package com.yxk.bootvueshop.tool;

import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * Created by baipan
 * Date: 2019/11/28
 * BeanMapper
 */
public interface BeanMapper {

    /**
     * 单实体映射
     */
    <S extends Serializable, T extends Serializable> T map(S source, Class<T> target);


    /**
     * 单实体映射
     * source to target
     * @param coverNull 是否将source中的null值映射到target对象
     */
    <S extends Serializable, T extends Serializable> T map(S source, T target, boolean coverNull);


    /**
     * 列表映射
     */
    <S extends Serializable, T extends Serializable> List<T> mapList(Collection<S> source, Class<T> target);


    /**
     * 自定义单实体转换
     */
    <S extends Serializable, T extends Serializable> T mapFunction(S source, Function<S, T> function);


    /**
     * 自定义列表映射
     */
    <S extends Collection, T extends Collection, M extends Class> T mapListFunction(S source,
                                                                                    M targetClazz,
                                                                                    BiFunction<S, M, T> function);

    /**
     * 根据clazzType获取Bean
     */
    <B> B getBean(Class<B> clazz);

    /**
     * 根据name获取Bean
     */
    <B> B getBean(String beanName, Class<B> clazz);

    /**
     * 根据注解及注解的值获取Bean
     */
    <B extends Annotation> List<Object> getBeanByAnnotation(Class<B> clazz);

}
